<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="商户名称">
              <a-select
                showSearch
                :value="value"
                placeholder="请输入商户名称"
                :defaultActiveFirstOption="false"
                :showArrow="false"
                :filterOption="false"
                @search="handleSearch"
                @change="handleChange"
                :notFoundContent="null"
                v-model="queryParam.sellerId"
              >
                <a-select-option  value="">请选择商户名</a-select-option>
                <a-select-option v-for="d in data" :key="d.value">{{d.text}}</a-select-option>
              </a-select>

            </a-form-item>
          </a-col>
<!--        <template v-if="toggleSearchStatus">-->
<!--          <a-col :md="6" :sm="8">-->
<!--            <a-form-item label="提现结果">-->
<!--              <a-select placeholder="请选择提现结果" v-model="queryParam.status">-->
<!--                <a-select-option  value="">请选择提现结果</a-select-option>-->
<!--                <a-select-option  value="0">审核中</a-select-option>-->
<!--                <a-select-option  value="1">提现成功</a-select-option>-->
<!--                <a-select-option  value="2">提现失败</a-select-option>-->
<!--              </a-select>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          </template>-->
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('提现信息记录表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetails(record)">详情</a>

<!--          <a-divider type="vertical" />-->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <cashInfoLog-modal ref="modalForm" @ok="modalFormOk"></cashInfoLog-modal>
  </a-card>
</template>

<script>
  import CashInfoLogModal from './modules/CashInfoLogModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import querystring from 'querystring';
  import { getAction } from '@/api/manage'

  let timeout;
  let currentValue;

  function fetch(value, callback) {
    if (timeout) {
      clearTimeout(timeout);
      timeout = null;
    }
    currentValue = value;

    function fake() {
      const str = querystring.encode({
        code: 'utf-8',
        q: value,
      });
      getAction(`/seller/web/list?username${str}`)
        .then(d => {
          if (currentValue === value) {
            const result = d.result.records;
            const data = [];
            result.forEach(r => {
              data.push({
                value: r.id,
                text: r.username,
              });
            });
            callback(data);
          }
        });
    }

    timeout = setTimeout(fake, 300);
  }

  export default {
    name: "CashInfoLogList",
    mixins:[
      JeecgListMixin,
    ],
    components: {
      CashInfoLogModal
    },
    data () {
      return {
        data: [],
        value: "",
        description: '提现信息记录表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '商户名称',
            align:"center",
            dataIndex: 'sellerId'
           },
		   {
            title: '提现金额',
            align:"center",
            dataIndex: 'presentPrice',
            customRender: text => {
                return text / 100
            }
           },
		   {
            title: '提现结果',
            align:"center",
            dataIndex: 'result',
            customRender: text => {
             if(text == 0){
               return '审核中'
             }else if (text == 1){
               return '提现成功'
             }else if (text == 2){
               return '提现失败'
             }
            }
           },
		   {
            title: '审核人',
            align:"center",
            dataIndex: 'adminUserId'
           },
          {
            title: '提现时间',
            align:"center",
            dataIndex: 'createTime'
          },

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/cash/list",
          delete: "/cash/delete",
          deleteBatch: "/cash/deleteBatch",
          exportXlsUrl: "cash/exportXls",
          importExcelUrl: "cash/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      handleSearch(value) {
        fetch(value, data => (this.data = data));
      },
      handleChange(value) {
        console.log(value);
        this.value = value;
        fetch(value, data => (this.data = data));
      },
      handleDetails(record) {
        //路由传参
        this.$router.push({path:'/cashInfo/modules', query:{record}});
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>